package de.jadehs.cosima.converters;

import org.jgrapht.DirectedGraph;
import org.jgrapht.graph.DirectedMultigraph;

import de.jadehs.cosima.IConverter;
import de.jadehs.cosima.State;
import de.jadehs.cosima.Transition;
import de.jadehs.cosima.TransitionsTable;

public class TransitionsTableToDirectedGraphConverter implements
		IConverter<TransitionsTable, DirectedGraph<State, Transition>> {
	public static final TransitionsTableToDirectedGraphConverter INSTANCE = new TransitionsTableToDirectedGraphConverter();

	public DirectedGraph<State, Transition> convert(TransitionsTable dfa) {
		DirectedGraph<State, Transition> graph = new DirectedMultigraph<State, Transition>(
				Transition.class);

		for (Transition t : dfa.getTransitions()) {
			graph.addVertex(t.getStart());
			graph.addVertex(t.getEnd());
			graph.addEdge(t.getStart(), t.getEnd(), t);
		}

		return graph;
	}
}
